package com.supms.course.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.supms.course.domain.CourseTargetEval;
import com.supms.course.domain.TestReviewEval;
import com.supms.course.domain.TestReviewItems;
import com.supms.course.mapper.CourseTargetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.supms.course.mapper.CourseTargetItemMapper;
import com.supms.course.domain.CourseTargetItem;
import com.supms.course.service.ICourseTargetItemService;

/**
 * 课程目标达成度评价项Service业务层处理
 * 
 * @author LiangHao
 * @date 2022-03-11
 */
@Service
public class CourseTargetItemServiceImpl implements ICourseTargetItemService 
{
    @Autowired
    private CourseTargetItemMapper courseTargetItemMapper;

    @Autowired
    private CourseTargetMapper courseTargetMapper;

    /**
     * 查询课程目标达成度评价项
     * 
     * @param id 课程目标达成度评价项主键
     * @return 课程目标达成度评价项
     */
    @Override
    public CourseTargetItem selectCourseTargetItemById(Long id)
    {
        return courseTargetItemMapper.selectCourseTargetItemById(id);
    }

    /**
     * 查询课程目标达成度评价项列表
     * 
     * @param courseTargetItem 课程目标达成度评价项
     * @return 课程目标达成度评价项
     */
    @Override
    public List<CourseTargetItem> selectCourseTargetItemList(CourseTargetItem courseTargetItem)
    {
        return courseTargetItemMapper.selectCourseTargetItemList(courseTargetItem);
    }

    /**
     * 新增课程目标达成度评价项
     * 
     * @param courseTargetItem 课程目标达成度评价项
     * @return 结果
     */
    @Override
    public int insertCourseTargetItem(CourseTargetItem courseTargetItem)
    {
        courseTargetItem.setCreateTime(DateUtils.getNowDate());
        return courseTargetItemMapper.insertCourseTargetItem(courseTargetItem);
    }

    /**
     * 修改课程目标达成度评价项
     * 
     * @param courseTargetItem 课程目标达成度评价项
     * @return 结果
     */
    @Override
    public int updateCourseTargetItem(CourseTargetItem courseTargetItem)
    {
        courseTargetItem.setUpdateTime(DateUtils.getNowDate());
        return courseTargetItemMapper.updateCourseTargetItem(courseTargetItem);
    }

    /**
     * 批量删除课程目标达成度评价项
     * 
     * @param ids 需要删除的课程目标达成度评价项主键
     * @return 结果
     */
    @Override
    public int deleteCourseTargetItemByIds(Long[] ids)
    {
        return courseTargetItemMapper.deleteCourseTargetItemByIds(ids);
    }

    /**
     * 删除课程目标达成度评价项信息
     * 
     * @param id 课程目标达成度评价项主键
     * @return 结果
     */
    @Override
    public int deleteCourseTargetItemById(Long id)
    {
        return courseTargetItemMapper.deleteCourseTargetItemById(id);
    }

    /**
     * 添加本科课程目标达成度评价（添加中间表）
     * @param courseTargetItemList 接收到已评价的评价表
     * @return 结果
     */
    @Override
    public int addCourseTargetEval(List<CourseTargetItem> courseTargetItemList) {
        List<CourseTargetEval> courseTargetEvalList = new ArrayList<>();
        Long courseTargetId = null;

        for (CourseTargetItem courseTargetItem : courseTargetItemList) {
            if (courseTargetItem.getMySituation() != null) {
                CourseTargetEval courseTargetEval = new CourseTargetEval();
                courseTargetId = courseTargetItem.getCourseTargetId();

                courseTargetEval.setCourseTargetId(courseTargetId);
                courseTargetEval.setCourseTargetItemId(courseTargetItem.getId());
                courseTargetEval.setSituation(courseTargetItem.getMySituation());
                courseTargetEval.setCreateTime(DateUtils.getNowDate());
                // 将收集到的评价数据收集到评价表对象，并将对象一条一条放到列表中
                courseTargetEvalList.add(courseTargetEval);
            } else return 0;
        }

        // 将本科课程目标达成度检查表中的评价标记改为已评价（"1"）
        courseTargetMapper.updateCourseTargetEvalFlagById(courseTargetId);
        return courseTargetItemMapper.addCourseTargetEval(courseTargetEvalList);
    }
}
